//
//  SoundMenu.h
//  SoundMenu: Menu oara
//
//  Created by Enric Vergara on 20.10.12. 
//  Copyright OWLAB 2010. All rights reserved.
// Import the interfaces

#import "SoundMenu.h"
#import "SoundManager.h"

// CRaiseMenu implementation
@implementation CSoundMenu



// on "init" you need to initialize your instance
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if ((self = [super init]))
    {
       //CGSize screenSize = [[CCDirector sharedDirector] winSize];
        CGPoint center = CGPointMake(0,0);
        //Definim el tapete del joc
        m_Background = [CCSprite spriteWithFile:@"menuExit_background.JPG"]; 
        m_Background.position =center;
        [self addChild:m_Background];

        [CCMenuItemFont setFontName:@"Arial"];
        [CCMenuItemFont setFontSize:40];
        m_Button_More = [CCMenuItemFont itemFromString:@"(+)" target:self selector:@selector(menuMore:)];
		m_Button_More.position =  CGPointMake( 30, -20);
        
        m_Button_Less = [CCMenuItemFont itemFromString:@"(-)" target:self selector:@selector(menuLess:)];
        m_Button_Less.position =  CGPointMake(-30, -20);

        m_Button_Accept = [CCMenuItemFont itemFromString:NSLocalizedString(@"Accept", @"") target:self selector:@selector(menuAccept:)];
        m_Button_Accept.position =  CGPointMake(0, -70);

        
        
        // create the menu using the items
        m_Menu = [CCMenu menuWithItems:m_Button_More, m_Button_Less, m_Button_Accept, nil];
        m_Menu.position = center;
        [self addChild:m_Menu];
        m_Menu.visible = true;

        float volume = [[SoundManager sharedInstance] getGeneralSoundFXVolume];
        //label indicant Current Sound: XXX
        m_sTitleLabel = [CCLabel labelWithString: [NSLocalizedString(@"CurrentSound", @"") stringByAppendingString:[NSString stringWithFormat: @"%f", volume]] fontName:@"Arial" fontSize:40];
        [m_sTitleLabel setColor:ccc3(0,0,0)];
        [m_sTitleLabel setPosition:CGPointMake(center.x,center.y + 50)];
        [self addChild: m_sTitleLabel];
        
        
		// must be enabled if you want to receive touch events!
		self.isTouchEnabled = YES;
	}
	return self;
}


-(void) ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{

}

-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}

-(void) menuMore: (id) sender
{
    if (!self.visible) return;
    
    float l_fxVolume = [[SoundManager sharedInstance] getGeneralSoundFXVolume];
    l_fxVolume += 0.1f;
    
    if (l_fxVolume > 1.f)
    {
        l_fxVolume = 1.f;
    }
    else
    {
        [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_SHOW_CARDS];
    }
    
    [[SoundManager sharedInstance] setSoundFXVolume:l_fxVolume];

    [m_sTitleLabel setString:[NSString stringWithFormat:@"%@%f",NSLocalizedString(@"CurrentSound", @""),l_fxVolume]];
}

-(void) menuLess: (id) sender
{
    if (!self.visible) return;
    
    float l_fxVolume = [[SoundManager sharedInstance] getGeneralSoundFXVolume];
    l_fxVolume -= 0.1f;
    
    if (l_fxVolume < 0.f)
    {
        l_fxVolume = 0.f;
    }
    else
    {
        [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_SHOW_CARDS];
    }
    
    [[SoundManager sharedInstance] setSoundFXVolume:l_fxVolume];    
    [m_sTitleLabel setString:[NSString stringWithFormat:@"%@%f",NSLocalizedString(@"CurrentSound", @""),l_fxVolume]];
}

-(void) menuAccept: (id) sender
{
    if (!self.visible) return;
    
    self.visible = false;    
    
    [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_NEXT];
}



// on "dealloc" you need to release all your retained objects
-(void) dealloc
{
	// don't forget to call "super dealloc"
	[super dealloc];
}

@end
